import java.util.Arrays;
import java.util.Random;

/**
 * Created with IntelliJ IDEA
 * Description
 * User: 王杰
 * Date: 2025-06-07
 * Time: 14:30
 */
public class Test {
    public static void orderArray(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = i;
//             array[i] = array.length - i; //逆序
        }
    }

    public static void noOrderArray(int[] array) {
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(100000);
        }
    }

    /**
     * 测试简单的数据能否执行，测试算法是否正确
     */
    public static void testSimple() {
        int[] array = {9, 1, 2, 5, 7, 4, 8, 6, 3, 5};
        System.out.println("排序前 " + Arrays.toString(array));

//        Sort.insertSort(array);
//        Sort.shellSort(array);
//        Sort.selectSort1(array);
//        Sort.heapSort(array);
//        Sort.quickSort(array);
        Sort.mergeSort(array);
        System.out.println("排序后 " + Arrays.toString(array));
    }

    public static void main(String[] args) {
//        testSimple();
         testOther();
    }

    public static void testOther() {
        int[] array = new int[10_0000];
//        orderArray(array);
        noOrderArray(array);
//        testInsert(array);
        testShellSort(array);
//        testSelectSort(array);
        testHeapSort(array);
        testQuickSort(array);
        testMergeSort(array);
    }

    public static void testInsert(int[] array) {
        array = Arrays.copyOf(array, array.length);
        long startTime = System.currentTimeMillis();
        Sort.insertSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("直接插入排序耗时：" + (endTime - startTime));
    }

    public static void testShellSort(int[] array) {
        array = Arrays.copyOf(array, array.length);
        long startTime = System.currentTimeMillis();
        Sort.shellSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔排序耗时：" + (endTime - startTime));
    }

    public static void testSelectSort(int[] array) {
        array = Arrays.copyOf(array, array.length);
        long startTime = System.currentTimeMillis();
        Sort.selectSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("选择排序耗时：" + (endTime - startTime));
    }

    public static void testHeapSort(int[] array) {
        array = Arrays.copyOf(array, array.length);
        long startTime = System.currentTimeMillis();
        Sort.heapSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("堆排序耗时：" + (endTime - startTime));
    }


    public static void testQuickSort(int[] array) {
        array = Arrays.copyOf(array, array.length);
        long startTime = System.currentTimeMillis();
        Sort.quickSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("快速排序耗时：" + (endTime - startTime));
    }

    public static void testMergeSort(int[] array) {
        array = Arrays.copyOf(array, array.length);
        long startTime = System.currentTimeMillis();
        Sort.mergeSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("归并排序耗时：" + (endTime - startTime));
    }
}
